export default {
  spu_name: [{ required: true, message: "属性不能为空", trigger: "blur" }],
  unit: [{ required: true, message: "单位不能为空", trigger: "blur" }],
  package_num: [
    { required: true, message: "包装数量不能为空", trigger: "blur" },
    {
      pattern: /^(\d+\.?)?\d{0,2}$/,
      message: "请输入整数和小数",
      trigger: "blur"
    }
  ],
  // goods_spu_code: [
  //   { required: true, message: '条码(SKU)不能为空', trigger: 'blur' },
  // ],
  market_price: [
    { required: true, message: "市场价不能为空", trigger: "blur" },
    {
      pattern: /^(\d+\.?)?\d{0,2}$/,
      message: "请输入整数和小数",
      trigger: "blur"
    }
  ],
  discount: [
    { required: true, message: "折扣不能为空", trigger: "blur" },
    {
      // pattern: /^(0\.(0[0-9]|[1-9]{1,2}|[1-9]0)$)|^1$/,
      pattern: /^0\.[0-9]{1,2}$|^0{1}$|^1{1}$|^1\.[0]{1,2}$/,
      message: "请输入0到1范围内且保留两位小数",
      trigger: "blur"
    }
  ],
  attrition_rate: [
    { required: true, message: "损耗率不能为空", trigger: "blur" },
    {
      pattern: /^(\d+\.?)?\d{0,2}$/,
      message: "请输入整数和小数",
      trigger: "blur"
    }
  ],
  purchase_price: [
    { required: true, message: "采购价不能为空", trigger: "blur" },
    {
      pattern: /^(\d+\.?)?\d{0,2}$/,
      message: "请输入整数和小数",
      trigger: "blur"
    }
  ],
  inventory_price: [
    { required: true, message: "库存价不能为空", trigger: "blur" },
    {
      pattern: /^(\d+\.?)?\d{0,2}$/,
      message: "请输入整数和小数",
      trigger: "blur"
    }
  ],
  minimum: [
    { required: true, message: "起订量不能为空", trigger: "blur" },
    {
      pattern: /^(\d+\.?)?\d{0,2}$/,
      message: "请输入整数和小数",
      trigger: "blur"
    }
  ],
  designated_inventory: [
    { required: true, message: "指定库存不能为空", trigger: "blur" },
    {
      pattern: /^(\d+\.?)?\d{0,2}$/,
      message: "请输入整数和小数",
      trigger: "blur"
    }
  ],
  tolerance: [
    {
      validator: (rule, value, callback) => {
        if (!value) {
          callback();
        }
        if (isNaN(+value)) {
          return callback(new Error("请输入正确的数值"));
        } else if (value <= 0 || value > 100) {
          return callback(new Error("请输入1-100以内的数值"));
        } else {
          callback();
        }
      },
      trigger: "blur"
    }
  ],
  discount: [
    {
      validator: (rule, value, callback) => {
        if (!Math.ceil(value)) {
          callback();
        }
        if (isNaN(+value)) {
          return callback(new Error("请输入正确的数值"));
        } else if (value < 0.001 || value > 10) {
          return callback(new Error("请输入0.001-10以内的数值"));
        } else {
          callback();
        }
      },
      trigger: "blur"
    }
  ],

  attrition_rate: [
    {
      validator: (rule, value, callback) => {
        if (!value) {
          callback();
        }
        if (isNaN(+value)) {
          return callback(new Error("请输入正确的数值"));
        } else if (value <= 0 || value > 100) {
          return callback(new Error("请输入1-100以内的数值"));
        } else {
          callback();
        }
      },
      trigger: "blur"
    }
  ]
};
